package threadLocal;

/**
 * @author 帅小伙
 * @date 2022/3/13
 * @description
 */
public class Demo02 {

    ThreadLocal<String> threadLocal = new ThreadLocal<>();

    private  String content;

    public String getContent() {
        return content;
        //return threadLocal.get();
    }

    public void setContent(String content) {
       this.content = content;
        //threadLocal.set(content);
    }

    public static void main(String[] args) {
        Demo02 demo = new Demo02();

        //会获取到其他线程的数据
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                // x
                synchronized(Demo02.class) {
                    demo.setContent(Thread.currentThread().getName()+"的数据");
                    System.out.println("---------");
                    System.out.println(Thread.currentThread().getName()+"---->"+demo.getContent());
                }

            },"线程"+i).start();

        }
    }

}
